Lab assignment 5

Part 1

  1. Identify 4 mebers of Java Collection Class or Interfaces

    1. List
    2. Set
    3. Queue
    4. Stack
  2. Analyse these 4 by explaining two key characteristics of each

    1. List

      1. Can allow duplicate elements.
      2. Allows you to have null elements.
    2. Set

      1. Does not allow duplicate elements.
      2. Models a matheatical set.
    3. Queue

      1. First element that enters a queue is the first one to be removed.
      2. There are two different classes that are used to implement the queue interface.
    4. Stack

      1. First element that enters a stack is the last one to be removed.
      2. Has methods like push(E item) and pop(E item).

Part 2

  1. What is your understanding of types in traingle braces.

    1. It specifies the data type of element that can be placed in the interface.
    2. String represents the string class, which will only allow strings to be placed in the List interface.
    3. String and Integer represent the key-value paring for the map interface.
  2. This is legal because the ArrayList collection implements the List interface.

  3. ArrayList and LinkedList both implement the list interface as general purpose implementations.CopyOnWriteArrayList is a special-purpose list implementation. Classes like HashMap, TreeMap, and LinkedMap are implementations of the Map interface.

--- title: Animal example --- classDiagram note "From Duck till Zebra" Animal <|-- Duck note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging" Animal <|-- Fish Animal <|-- Zebra Animal : +int age Animal : +String gender Animal: +isMammal() Animal: +mate() class Duck{ +String beakColor +swim() +quack() } class Fish{ -int sizeInFeet -canEat() } class Zebra{ +bool is_wild +run() }